#include <iostream>
#include <algorithm>
using namespace std;

const int N = 110;
int f[N][N];
int dx[2] = {-1, 0}, dy[2] = {0, -1};

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int r, c;
        cin >> r >> c;
        for (int i = 1; i <= r; ++i)
            for (int j = 1; j <= c; ++j)
                cin >> f[i][j];
        for (int i = 1; i <= r; ++i)
            for (int j = 1; j <= c; ++j)
            {
                int ans = 0;
                for (int k = 0; k < 2; ++k)
                {
                    int xx = i + dx[k], yy = j + dy[k];
                    if (xx >= 1 && xx <= r && yy >= 1 && yy <= c)
                        ans = max(ans, f[xx][yy]);
                }
                f[i][j] += ans;
            }
        cout << f[r][c] << endl;
    }
    return 0;
}
